// 商品接口管理
import request from "@/utils/request";

import type {
  GoodsEditResponse,
  GoodsPageRequest,
  GoodsPageResponse,
  GoodsResponse,
  GoodsType,
} from "./types";

enum API {
  GOODS_PAGE = "/wx/goods/page",
  GOODS_CREATE_OR_EDIT = "/wx/goods/createOrEdit",
  GOODS_GET_BY_ID = "/wx/goods/getById",
  GOODS_REMOVE = "/wx/goods/remove",
  GOODS_CHANGE_STATUS = "/wx/goods/changeStatus",
}

export const goodsPage = (data: GoodsPageRequest) =>
  request.post<any, GoodsPageResponse>(API.GOODS_PAGE, data);

export const goodsCreateOrEdit = (data: GoodsType) =>
  request.post<any, GoodsEditResponse>(API.GOODS_CREATE_OR_EDIT, data);

export const goodsGetById = (id: number) =>
  request.get<any, GoodsResponse>(API.GOODS_GET_BY_ID + `/${id}`);

export const goodsRemove = (id: number) =>
  request.delete<any, GoodsEditResponse>(API.GOODS_REMOVE + `/${id}`);

export const goodsChangeStatus = (id: number, status: number) =>
  request.post<any, GoodsEditResponse>(
    API.GOODS_CHANGE_STATUS + `/${id}` + `/${status}`
  );
